//
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

div(ng-if="checkpoint")
  table.table.table-inner
    thead
      tr
        td #[strong ID]
        td #[strong Status]
        td #[strong Acknowledged]
        td #[strong Trigger Time]
        td #[strong Latest Acknowledgement]
        td(ng-if="checkpoint['failure_timestamp']") #[strong Failure Time]
        td #[strong End to End Duration]
        td #[strong State Size]
        td #[strong Buffered During Alignment]
        td(ng-if="checkpoint['status'] == 'COMPLETED'") #[strong Discarded]
        td(ng-if="checkpoint['external_path']") #[strong Path]
        td(ng-if="checkpoint['failure_message']") #[strong Failure Message]
    tbody
      tr
        td {{ checkpoint['id'] }}
        td(ng-if="checkpoint['status'] == 'IN_PROGRESS'") #[i(aria-hidden="true").fa.fa-circle-o-notch.fa-spin.fa-fw] In progress #[i(ng-if="checkpoint['is_savepoint']") savepoint]
        td(ng-if="checkpoint['status'] == 'COMPLETED'") #[i(aria-hidden="true").fa.fa-check] Completed #[i(ng-if="checkpoint['is_savepoint']") savepoint]
        td(ng-if="checkpoint['status'] == 'FAILED'") #[i(aria-hidden="true").fa.fa-remove] Failed #[i(ng-if="checkpoint['is_savepoint']") savepoint]
        td {{ checkpoint['num_acknowledged_subtasks'] }}/{{ checkpoint['num_subtasks'] }} ({{ checkpoint['num_acknowledged_subtasks']/checkpoint['num_subtasks'] | percentage }})
        td {{ checkpoint['trigger_timestamp'] | amDateFormat:'H:mm:ss' }}
        td(ng-if="checkpoint['latest_ack_timestamp'] >= 0") {{ checkpoint['latest_ack_timestamp'] | amDateFormat:'H:mm:ss' }}
        td(ng-if="checkpoint['latest_ack_timestamp'] < 0") n/a
        td(ng-if="checkpoint['failure_timestamp']") {{ checkpoint['failure_timestamp'] | amDateFormat:'H:mm:ss' }}
        td(ng-if="checkpoint['end_to_end_duration'] >= 0") {{ checkpoint['end_to_end_duration'] | humanizeDuration }}
        td(ng-if="heckpoint['end_to_end_duration'] < 0") n/a
        td {{ checkpoint['state_size'] | humanizeBytes }}
        td  {{ checkpoint['alignment_buffered'] | humanizeBytes }}
        td(ng-if="checkpoint['status'] == 'COMPLETED'") #[span(ng-if="checkpoint['discarded']") Yes]#[span(ng-if="!checkpoint['discarded']") No]
        td(ng-if="checkpoint['external_path']") {{ checkpoint['external_path'] }}
        td(ng-if="checkpoint['status'] == 'FAILED' && checkpoint['failure_message']") {{ checkpoint['failure_message'] }}
        td(ng-if="checkpoint['status'] == 'FAILED' && !checkpoint['failure_message']") n/a

  h4 Operators
  table.table.table-body-hover.table-clickable.table-activable.subtask-details
    thead
      tr
        td #[strong Name]
        td #[strong Acknowledged]
        td #[strong Latest Acknowledgment]
        td #[strong End to End Duration]
        td #[strong State Size]
        td #[strong Buffered During Alignment]
        td
    tbody(ng-repeat="v in job.vertices" ng-class="{ active: v.id == nodeid }" ng-click="changeNode(v.id)")
      tr(ng-if="v.type == 'regular'")
        td {{ v.name | humanizeText }}
        td {{ checkpoint['tasks'][v.id]['num_acknowledged_subtasks'] }}/{{ checkpoint['tasks'][v.id]['num_subtasks'] }} ({{ checkpoint['tasks'][v.id]['num_acknowledged_subtasks']/checkpoint['tasks'][v.id]['num_subtasks'] | percentage }})
        td(ng-if="checkpoint['tasks'][v.id]['latest_ack_timestamp'] >= 0") {{ checkpoint['tasks'][v.id]['latest_ack_timestamp'] | amDateFormat:'H:mm:ss' }}
        td(ng-if="checkpoint['tasks'][v.id]['latest_ack_timestamp'] < 0") n/a
        td(ng-if="checkpoint['tasks'][v.id]['end_to_end_duration'] >= 0") {{ checkpoint['tasks'][v.id]['end_to_end_duration'] | humanizeDuration }}
        td(ng-if="checkpoint['tasks'][v.id]['end_to_end_duration'] < 0") n/a
        td {{ checkpoint['tasks'][v.id]['state_size'] | humanizeBytes }}
        td {{ checkpoint['tasks'][v.id]['alignment_buffered'] | humanizeBytes }}
        td
          div(ng-if="!nodeid || v.id != nodeid")
            a.btn.btn-default(ng-click="toggleFold()")
              | Show Subtasks
              = ' '
              i.fa.fa-chevron-down
          div(ng-if="nodeid && v.id == nodeid")
            a.btn.btn-default(ng-click="toggleFold()")
              | Hide Subtasks
              = ' '
              i.fa.fa-chevron-up
      tr(ng-if="nodeid && v.id == nodeid")
        td(colspan=7)
          table.table.table-body-hover.table-inner.subtask-details
            thead(ng-if="subtaskDetails[v.id]['summary']")
              tr
                td
                td
                td #[strong End to End Duration]
                td #[strong State Size]
                td #[strong Checkpoint Duration (Sync)]
                td #[strong Checkpoint Duration (Async)]
                td #[strong Alignment Buffered]
                td #[strong Alignment Duration]
              tr
                td
                td #[strong Minimum]
                td {{ subtaskDetails[v.id]['summary']['end_to_end_duration']['min'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['state_size']['min'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['sync']['min'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['async']['min'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['buffered']['min'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['duration']['min'] | humanizeDuration }}
              tr
                td
                td #[strong Average]
                td {{ subtaskDetails[v.id]['summary']['end_to_end_duration']['avg'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['state_size']['avg'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['sync']['avg'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['async']['avg'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['buffered']['avg'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['duration']['avg'] | humanizeDuration }}
              tr
                td
                td #[strong Maximum]
                td {{ subtaskDetails[v.id]['summary']['end_to_end_duration']['max'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['state_size']['max'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['sync']['max'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['checkpoint_duration']['async']['max'] | humanizeDuration }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['buffered']['max'] | humanizeBytes }}
                td {{ subtaskDetails[v.id]['summary']['alignment']['duration']['max'] | humanizeDuration }}
              tr.blank
                td(colspan=8)
            thead
              tr
                td #[strong Subtask #]
                td #[strong Acknowledgement Time]
                td #[strong End to End Duration]
                td #[strong State Size]
                td #[strong Checkpoint Duration (Sync)]
                td #[strong Checkpoint Duration (Async)]
                td #[strong Alignment Buffered]
                td #[strong Alignment Duration]
            tbody
              tr(ng-repeat="subtask in subtaskDetails[v.id]['subtasks']")
                td {{ subtask['index'] + 1 }}
                td(ng-if-start="subtask['status'] == 'completed'") {{ subtask['ack_timestamp'] | amDateFormat:'H:mm:ss' }}
                td {{ subtask['end_to_end_duration'] | humanizeDuration }}
                td {{ subtask['state_size'] | humanizeBytes }}
                td {{ subtask['checkpoint']['sync'] | humanizeDuration }}
                td {{ subtask['checkpoint']['async'] | humanizeDuration }}
                td {{ subtask['alignment']['buffered'] | humanizeBytes}}
                td(ng-if-end) {{ subtask['alignment']['duration'] | humanizeDuration }}
                td(ng-if="subtask['status'] == 'pending_or_failed'" colspan=7) n/a

div(ng-if="!checkpoint")
  p(ng-if="unknown_checkpoint" role="alert").alert.alert-danger
    strong Unknown or expired checkpoint ID.
  p(ng-if="!unknown_checkpoint" role="alert").alert.alert-info
    strong Waiting for response from JobManager with checkpoint details...
    = ' '
    i(aria-hidden="true").fa.fa-circle-o-notch.fa-spin.fa-fw
